<%'  ------------------------------------------------------------
  '  checkutil.asp 
  '  ------------------------------------------------------------
  '  VCS INFO:
  '  
  '  $Revision:   1.0  $
  '  $Date:   24 Mar 1998 17:47:12  $
  '  $Author:   shsieh  $
  '  $Workfile:   checkutil.asp  $
  '  ------------------------------------------------------------
  '  All Rights Reserved.  Copyright (c) 1988-1998 FileNET Corp.
  '  ------------------------------------------------------------
  '%>

<SCRIPT LANGUAGE="JavaScript">
<!--
function ReportError(inp, msg, defvalue)
{
	alert(msg);
	inp.focus();
	inp.value = defvalue;
	return false;
}

function CheckInteger(inp, defvalue, isemptyok, maxdigits)
{
	if (defvalue == null)
		defvalue = "";
	if (isemptyok == null)
		isemptyok = true;
	if (maxdigits == null)
		maxdigits = -1;

	var str = inp.value;
	var len = str.length;

	if (!isemptyok && len == 0)
		return ReportError(inp, "You must enter a number.", defvalue);

	for (var i=0; i < len; i++) {
		var ch = str.charAt(i);
		if ((ch > '9'  ) || (ch < '0'))
			return ReportError(inp, "Please enter a valid number.", defvalue);
	}

	if (len && maxdigits > 0 && len > maxdigits)
		return ReportError(inp, "You can only enter a " + maxdigits + "-digit number.", defvalue);

	return true;
}


function CheckString(inp, defvalue, isemptyok, maxchars, illegalchars)
{
	if (defvalue == null)
		defvalue = "";
	if (isemptyok == null)
		isemptyok = true;
	if (maxchars == null)
		maxchars = -1;
	if (illegalchars == null)
		illegalchars = "";

	var str = inp.value;
	var len = str.length;

	if (!isemptyok && len == 0)
		return ReportError(inp, "You must enter a string.", defvalue);

	for (var i=0; i < len; i++) {
		var ch = str.charAt(i);
		if (illegalchars.indexOf(ch) != -1)
			return ReportError(inp, "'" + ch + "' is not a valid character.", defvalue);
	}

	if (len && maxchars > 0 && len > maxchars)
		return ReportError(inp, "You can only enter a " + maxchars + "-character string.", defvalue);

	return true;
}


function CheckDate(inp, defvalue, isemptyok)
{
	if (defvalue == null)
		defvalue = "";
	if (isemptyok == null)
		isemptyok = true;

	var str = inp.value;
	var len = str.length;

	if (!isemptyok && len == 0)
		return ReportError(inp, "You must enter a date.", defvalue);

	return true;



	// TO BE ENHANCED/FIXED

	// mm/dd/yy [hh:mm:ss [A/PM]]
	if (len < 1) { 
		return true; // no string 
	}
	var sep = '/';
	var n1 = 0; // location of current separator
	var n2 = 0; // location of next separator
	var sMonth = "";
	var sDay = "";
	var sYear = "";
	var iDay = 0;
	var iMonth = 0;
	var iYear = 0;
	// check month value
	n2 = str.indexOf(sep, n1);	// get position of next separator
	sMonth = str.substring(n1, n2);
	n1 = n2+1;
	if ((n1 < len) && (n2 < str.lastIndexOf(sep))) {
		n2 = str.indexOf(sep, n1);	// get position of next separator
		sDay = str.substring(n1, n2);
		n1 = n2+1;
		if (n1 < len)
			sYear = str.substring(n1, len);
	}
	// message = "Month: " + sMonth + " Day: " + sDay + " year: " + sYear;
	// alert(message);
	if (sMonth != "") iMonth = parseInt(sMonth, 10);
	if (sDay != "") iDay = parseInt(sDay, 10);
	if (sYear != "") iYear = parseInt(sYear, 10);

	if ((iMonth < 1  ) || (iDay < 1) || (iYear == 0) ||
		(iMonth > 12  ) || (iDay > 31) || (iYear > 99) ) {
		alert ("You must enter a valid date mm/dd/yy.");
		inp.focus();
		inp.value = defvalue;
		return false;
	}
	return true;
}

//-->
</SCRIPT>
